<?php if(!defined('root_dir')) exit('Forbidden');
Class session_int {

    public function session_int() {
        global $cache;
        $this->lifetime = '604800'; //有效时间为1周
        $this->cache = $cache;
    }

    public function sess_open() {
       if(!$this->cache) {
           return false; 
       }
       return true; 
    }

    public function sess_close() {
        return true;
    }

    public function sess_read($sessid) {
        $cache_sessionid = 'sessionid_'.$sessid;
        $session_data = $this->cache->load($cache_sessionid);
        if ($session_data) {
            return $session_data;
        } else {
            return '';
        }
    }
    public function sess_write($sessionid, $sessiondata) {
        $cache_sessionid = 'sessionid_'.$sessionid;
        $session_data = $this->cache->load($cache_sessionid);
        if ($sessiondata) {
            $this->cache->save($sessiondata, $cache_sessionid, array(), $this->lifetime);
        } else {
            return false;
        }
    }
    public function sess_destroy($sessid) {
        $cache_sessionid = 'sessionid_'.$sessid;
        $this->cache->remove($cache_sessionid);
    }

    public function sess_gc() {
        //取消定时清除
        return true;
    }
    
     

}
$session = new session_int();
@session_set_save_handler(array(&$session,"sess_open"), 
                         array(&$session,"sess_close"), 
                         array(&$session,"sess_read"), 
                         array(&$session,"sess_write"), 
                         array(&$session,"sess_destroy"), 
                         array(&$session,"sess_gc")
       );
session_start();